--[[
从缓存短信列表KEYS[1]中读取[序列:号码],并读取其关联[KEYS[2]:序号:号码]HASH中的内容,返回指定长度的List

KEYS[1] : 缓存队列名称
KEYS[2] : hash key前缀, 和KEYS[1]读取的字符串组成完整的hash key
ARGV[1] : 返回的最大list长度

--]]

local cachequeuezset = KEYS[1]
local hashprefix = KEYS[2]
local from = tonumber(ARGV[1])
local to = tonumber(ARGV[2])
local array = {}
local index = 0

local list = redis.call("LRANGE", cachequeuezset, from, to)

for i,v in ipairs(list) do

    if (v ~= nil and v ~= "" and v ~= false) then
        local hashvalue = redis.call("hmget", hashprefix..":"..v, "Srv_node", "ServiceCode", "SmType", "User", "Smcont", "Reportflag", "recvTime", "RecvModuleName", "SendPort", "SerialSegment", "resptime", "respresult", "OrgSrvNode", "OrgSerialNo", "SendFeedbackResult")
        index = index +1
        array[index] = hashvalue
        redis.call("lrem", cachequeuezset, 0, v)
    else
        break
    end
    
    if (index >= to) then
        break
    end
end

return array